package com.hq.controller;

import com.github.pagehelper.PageInfo;
import com.hq.pojo.Appointment;
import com.hq.pojo.Doctor;
import com.hq.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("/selectAllUser")
    @ResponseBody
    public PageInfo<Appointment> selectAllUser(int pageNum, int pageSize) {
        if (pageNum == -1)
            pageNum = 1;
        return adminService.selectAllUser(pageNum, pageSize);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> adminUpdate(String username, String pwd, String newPass, String renewPass) {
        return adminService.updatePass(username, pwd, newPass, renewPass);
    }

    @RequestMapping("/selectAllDoctor")
    @ResponseBody
    public PageInfo<Doctor> selectAllDoctor(int pageNum, int pageSize) {
        if (pageNum == -1)
            pageNum = 1;
        return adminService.selectAllDoctor(pageNum, pageSize);
    }

    @RequestMapping("/lookAppoint")
    @ResponseBody
    public PageInfo<Appointment> lookAppoint(String username) {
        return adminService.selectDoctorAllUser(username);
    }

    //删除Appoint
    @RequestMapping("/delAppoint")
    public void delAppoint(Integer appointId) {
        adminService.delAppoint(appointId);
    }

    //删除Doctor
    @RequestMapping("/delDoctor")
    public void delDoctor(Integer doctorId) {
        adminService.delDoctor(doctorId);
    }
}
